﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using ComLib.ConfigService;
using ComLib.ComFun;
using System.Drawing;
using ComLib.ComType;
using System.IO;
using System.Reflection;

namespace YSLPages
{
    /// <summary>
    /// 人员核查选项
    /// </summary>
    [XmlRootAttribute("PersonCheckOption", Namespace = "YSLPages", IsNullable = false)]
    public class PersonCheckOption : XmlSerializeBase
    {
        [XmlIgnore]
        public override string ConfigDirectory
        {
            get
            {
                string directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase);
                directory = directory.Substring(6);
                return directory;
            }
        }

        public PersonCheckOption()
        {

        }     

        /// <summary>
        /// 是否检查国家工作人员
        /// </summary>
        private bool _enableCheckOffical = false;
        public bool EnabledCheckOffical
        {
            get { return _enableCheckOffical; }
            set { _enableCheckOffical = value; }
        }

        public override bool Serialize()
        {
            return Serializer.SaveToXml(ConfigFilePath, this);
        }
     
        public override bool Load()
        {
            PersonCheckOption obj = (PersonCheckOption)Serializer.LoadFromXml(ConfigFilePath, this.GetType());
            if (obj != null)
            {
                this._enableCheckOffical = obj._enableCheckOffical;
                this._nVer = obj._nVer;   
                return true;
            }
            else
            {
                ErrorMessage = Serializer.Message;
                return false;
            }
        }

        public override string ToString()
        {       
            StringBuilder builder = new StringBuilder("人员核查选项: ");
            FillFieldValueStringDelegate FillString =
              (string field, object val) =>
              {
                  builder.Append("[");
                  builder.Append(field);
                  builder.Append("]: ");
                  builder.Append(val.ToString() + "; ");
              };
            FillString("是否检查国家工作人员:", _enableCheckOffical ? "是" : "否");
            return builder.ToString();
        }
    }
}
